public class Solution413 {
    public int numberOfArithmeticSlices(int[] nums) {
        int ans=0;
        int t=0;
        for (int i=2;i<nums.length;i++){
            if (nums[i]-nums[i-1]!=nums[i-1]-nums[i-2]){
                ans=ans+(t+1)*t/2;
                t=0;
            }else{
                t++;
            }
        }
        ans=ans+(t+1)*t/2;
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution413().numberOfArithmeticSlices(new int[]{1,2,3,4}));
    }
}
